<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>注册 - 快递管理系统</title>
    <link th:href="@{/webjars/bootstrap/5.3.2/css/bootstrap.min.css}" rel="stylesheet">
    <style>
        body {
            background-color: #f8f9fa;
        }
        .register-container {
            max-width: 500px;
            margin: 50px auto;
            padding: 30px;
            background-color: white;
            border-radius: 8px;
            box-shadow: 0 0 15px rgba(0,0,0,0.1);
        }
        .register-title {
            text-align: center;
            margin-bottom: 30px;
            color: #333;
        }
        .form-label {
            font-weight: 500;
            color: #555;
        }
        .btn-register {
            background-color: #28a745;
            border-color: #28a745;
            font-weight: 500;
        }
        .btn-register:hover {
            background-color: #218838;
            border-color: #1e7e34;
        }
        .login-link {
            text-align: center;
            margin-top: 20px;
        }
        .login-link a {
            color: #007bff;
            text-decoration: none;
        }
        .login-link a:hover {
            text-decoration: underline;
        }
    </style>
</head>
<body>
    <div class="container">
        <div class="register-container">
            <h2 class="register-title">用户注册</h2>
            
            <!-- 错误消息 -->
            <div th:if="${error}" class="alert alert-danger" th:text="${error}">
                错误消息
            </div>
            
            <!-- 成功消息 -->
            <div th:if="${message}" class="alert alert-success" th:text="${message}">
                成功消息
            </div>
            
            <form th:action="@{/register}" method="post" id="registerForm">
                <div class="mb-3">
                    <label for="username" class="form-label">用户名 <span class="text-danger">*</span></label>
                    <input type="text" class="form-control" id="username" name="username" 
                           required maxlength="50" placeholder="请输入用户名">
                    <div class="form-text">用户名用于登录，不能重复</div>
                </div>
                
                <div class="mb-3">
                    <label for="password" class="form-label">密码 <span class="text-danger">*</span></label>
                    <input type="password" class="form-control" id="password" name="password" 
                           required minlength="6" placeholder="请输入密码">
                    <div class="form-text">密码长度至少6位</div>
                </div>
                
                <div class="mb-3">
                    <label for="confirmPassword" class="form-label">确认密码 <span class="text-danger">*</span></label>
                    <input type="password" class="form-control" id="confirmPassword" name="confirmPassword" 
                           required minlength="6" placeholder="请再次输入密码">
                </div>
                
                <div class="mb-3">
                    <label for="realName" class="form-label">真实姓名 <span class="text-danger">*</span></label>
                    <input type="text" class="form-control" id="realName" name="realName" 
                           required maxlength="50" placeholder="请输入真实姓名">
                </div>
                
                <div class="mb-3">
                    <label for="phoneNumber" class="form-label">手机号码 <span class="text-danger">*</span></label>
                    <input type="tel" class="form-control" id="phoneNumber" name="phoneNumber" 
                           required pattern="^1[3-9]\d{9}$" placeholder="请输入手机号码">
                    <div class="form-text">请输入11位有效手机号码</div>
                </div>
                
                <div class="mb-3">
                    <label for="email" class="form-label">邮箱</label>
                    <input type="email" class="form-control" id="email" name="email" 
                           maxlength="100" placeholder="请输入邮箱（可选）">
                </div>
                
                <div class="d-grid">
                    <button type="submit" class="btn btn-register btn-lg">注册</button>
                </div>
            </form>
            
            <div class="login-link">
                <p>已有账户？<a th:href="@{/login}">立即登录</a></p>
            </div>
        </div>
    </div>
    
    <script th:src="@{/webjars/bootstrap/5.3.2/js/bootstrap.bundle.min.js}"></script>
    <script>
        document.addEventListener('DOMContentLoaded', function() {
            const form = document.getElementById('registerForm');
            const password = document.getElementById('password');
            const confirmPassword = document.getElementById('confirmPassword');
            
            // 表单提交验证
            form.addEventListener('submit', function(event) {
                if (password.value !== confirmPassword.value) {
                    event.preventDefault();
                    alert('两次输入的密码不一致，请重新输入');
                    confirmPassword.focus();
                    return false;
                }
                
                // 手机号码格式验证
                const phonePattern = /^1[3-9]\d{9}$/;
                const phoneInput = document.getElementById('phoneNumber');
                if (!phonePattern.test(phoneInput.value)) {
                    event.preventDefault();
                    alert('请输入正确的手机号码格式');
                    phoneInput.focus();
                    return false;
                }
            });
            
            // 密码确认实时验证
            confirmPassword.addEventListener('input', function() {
                if (password.value !== confirmPassword.value) {
                    confirmPassword.setCustomValidity('密码不一致');
                } else {
                    confirmPassword.setCustomValidity('');
                }
            });
        });
    </script>
</body>
</html> 